import { BuyBatchPanel } from "../shop/BuyBatchPanel";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { SPanicBuyItemMsg } from "../../../../Message/Game/SPanicBuyItemMsg";
import { ItemData } from "../../resource/info/ItemData";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class MallBuyBatchPanel
    
    export  class MallBuyBatchPanel extends BuyBatchPanel
    {
        constructor(arg1: ShopItemInfo=null)
        {
            super(arg1);
            return;
        }

        public /* override */ update(arg1: Object, ... rest): void
        {
            if (arg1 && arg1 is SPanicBuyItemMsg) 
            {
                this._panicBuyItemMsg = arg1 as SPanicBuyItemMsg;
                _itemData = new ItemData(this._panicBuyItemMsg.itemCode);
                _uint = EPrictUnit._EPriceUnitGold;
                _property = getPropertyByUnit(_uint);
                _unitPrice = this._panicBuyItemMsg.discount;
                this.initAmount();
                _totalPrice = _unitPrice * amount;
                _nameTxt.htmlText = ItemsUtil.getItemName(_itemData);
                _priceTxt.text = _unitPrice.toString();
                _propertyTxt.htmlText = _property.toString();
                _baseItem.itemData = _itemData;
                _priceImgName = GameDefConfig.instance.getEPrictUnitImg(_uint);
                _uintName = getUnitName(_uint);
                if (_priceImgName == "") 
                {
                    _unitBitmap.bitmapData = null;
                    _costBitmap.bitmapData = null;
                    _propertyBitmap.bitmapData = null;
                    _unitTxt.htmlText = _uintName;
                    _costUnitTxt.htmlText = _uintName;
                    _propertyUnitTxt.htmlText = _uintName;
                }
                else 
                {
                    _unitBitmapData = GlobalClass.getBitmapData(_priceImgName);
                    _unitBitmap.bitmapData = _unitBitmapData;
                    _costBitmap.bitmapData = _unitBitmapData;
                    _propertyBitmap.bitmapData = _unitBitmapData;
                    _unitTxt.text = "";
                    _costUnitTxt.text = "";
                    _propertyUnitTxt.text = "";
                }
                checkMoney();
            }
            return;
        }

        protected /* override */ initAmount(): void
        {
            var loc1=Cache.instance.shop.panicBuyDict[this._panicBuyItemMsg.itemCode];
            var loc2=this._panicBuyItemMsg.buyLimit - loc1;
            loc2 = loc2 < this._panicBuyItemMsg.leftAmount ? loc2 : this._panicBuyItemMsg.leftAmount;
            if (_property > loc2 * _unitPrice) 
            {
                amount = loc2;
            }
            else 
            {
                amount = Math.floor(_property / _unitPrice);
            }
            _numInput.currentNum = amount;
            _numInput.setMaxNum(loc2);
            return;
        }

        protected /* override */ onBuyBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (_property < _totalPrice) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(90273, _uintName));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PanicBuyItem, {"itemCode": this._panicBuyItemMsg.itemCode, "amount": _numInput.currentNum}));
            hide();
            return;
        }

        /* internal */ /* var */_panicBuyItemMsg: SPanicBuyItemMsg;
    }
